#!/bin/bash

${APP_SCRIPT_DIR}/mysql_config/port.sh
${APP_SCRIPT_DIR}/mysql_config/data_dir.sh
${START_SHELL}
PASSWORD_LINE=$(cat /var/log/mysqld.log | grep "A temporary password is generated for")
PASSWORD=${PASSWORD_LINE: -12}

${APP_SCRIPT_DIR}/mysql_config/root_password.sh ${PASSWORD}
if [ -z "${MYSQL_ROOT_PASSWORD}" ];
then
  echo "${PASSWORD}" >> ${APP_OUTPUT_DIR}/password.txt
  echo "mysql default password output to ${APP_OUTPUT_DIR}/password.txt"
  echo "If you want to remote_can_access,create database,launch sql_file, must reset your password"
else
  PASSWORD=${MYSQL_ROOT_PASSWORD}
  ${APP_SCRIPT_DIR}/mysql_config/remote_can_access.sh ${PASSWORD}
  ${APP_SCRIPT_DIR}/mysql_config/databases.sh ${PASSWORD}
  ${APP_SCRIPT_DIR}/mysql_config/sql_file.sh ${PASSWORD}
fi
${STOP_SHELL}